package com.g4.shoppingback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.g4.shoppingback.mapper.AddressMapper;
import com.g4.shoppingback.pojo.AddressInfo;
import com.g4.shoppingback.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;


@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressMapper addressMapper;



    @Override
    public void addAddressInfo(String address, int userId) {
        AddressInfo info = new AddressInfo();
        info.setAddress(address);
        info.setUserId(userId);

        addressMapper.insert(info);

    }

    @Override
    public void deleteAddress(int id) {

        addressMapper.deleteById(id);

    }

    @Override
    public void updateAddress(int addressId, String address, int userId) {
        AddressInfo info = new AddressInfo();
        info.setUserId(userId);
        info.setAddress(address);
        info.setId(addressId);

        addressMapper.updateById(info);

    }

    @Override
    public List<AddressInfo> selectAddress(int userId) {
        QueryWrapper  wrapper = new QueryWrapper();
        wrapper.in("userId" ,userId);

        return addressMapper.selectList(wrapper);
    }
}
